package org.thunms.copyright.version.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thunms.copyright.version.entity.CopyrightValidateEntity;
import org.thunms.copyright.version.service.CopyrightValidateService;
import org.thunms.framework.model.DataGrid;
import org.thunms.framework.model.DataGridJson;
/**
 * 版权管理平台
 * 版本注册子系统
 * 版本验证管理
 */
@Controller
@RequestMapping("/copyright/version/copyrightValidate")
public class CopyrightValidateController  {
	/**
	 * 列表页面
	 */
	private static final String LIST_PAGE="copyright/version/copyrightValidate/copyrightValidate_list";
	
	private static final Logger logger =LoggerFactory.getLogger(CopyrightValidateController.class);
	@RequestMapping
	public String index(){
		return LIST_PAGE;
		
	}
	
	@RequestMapping(value="/dataGridList")
	@ResponseBody
	public DataGridJson<CopyrightValidateEntity> dataGridList(DataGrid dg, CopyrightValidateEntity mode){
		return this.copyrightValidateService.getDataGridList(dg,mode);
	}
	

	
	
	@Autowired
	private CopyrightValidateService copyrightValidateService;

	
	@RequestMapping(value = "/downloadLicense")
	public void downloadLicense(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
		PrintWriter out = null;
		try {
			response.reset();
			response.setHeader("Content-Disposition", "attachment;filename=license.lip");
			response.setContentType("application/octet-stream; charset=utf-8");
			out = response.getWriter();
			out.write(copyrightValidateService.downloadLicense(id));
		} finally {
			if (out != null) {
				out.close();
			}
		}
	}

}
